<?php
/**
* @version $Id: contact.XML.php 6087 2006-12-24 18:59:57Z robs $
* @package Joomla
* @subpackage Contact
* @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.XML GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );


/**
* @package Joomla
* @subpackage Contact
*/
class XML_contact {

	function createNodeXML ( $name, $content) {
		echo "<".$name.">".$content."</".$name.">".chr(10);
	}

	function displaylist( &$categories, &$rows, $catid, $currentcat=NULL, &$params, $tabclass ) {
		global $Itemid, $mosConfig_live_site, $hide_js;

		if ( $params->get( 'page_title' ) ) {
			XML_contact::createNodeXML ("header",$currentcat->header); 
		}
		
			
			// show image
			if ( $currentcat->img ) {
				XML_contact::createNodeXML ("img",$currentcat->img);
			}
			
			XML_contact::createNodeXML ("descrip", $currentcat->descrip);
			if ( count( $rows ) ) {
				XML_contact::showTable( $params, $rows, $catid, $tabclass );
			}
		
			// Displays listing of Categories
			if ( ( $params->get( 'type' ) == 'category' ) && $params->get( 'other_cat' ) ) {
				XML_contact::showCategories( $params, $categories, $catid );
			} else if ( ( $params->get( 'type' ) == 'section' ) && $params->get( 'other_cat_section' ) ) {
				XML_contact::showCategories( $params, $categories, $catid );
			}
	}

	/**
	* Display Table of items
	*/
	function showTable( &$params, &$rows, $catid, $tabclass ) {
		global $mosConfig_live_site, $Itemid;
		/*if ( $params->get( 'headings' ) ) {
					echo _CONTACT_HEADER_NAME; 
				if ( $params->get( 'position' ) ) {
						createNodeXML ("contactHeaderPos",_CONTACT_HEADER_POS); 
				}
				if ( $params->get( 'email' ) ) {
						createNodeXML ("contactHeaderEmail",_CONTACT_HEADER_EMAIL); 
				}
				if ( $params->get( 'telephone' ) ) {
						createNodeXML ("contactHeaderPhone",_CONTACT_HEADER_PHONE); 
				}
				if ( $params->get( 'fax' ) ) {
						createNodeXML ("contactHeaderFax",_CONTACT_HEADER_FAX); 
				}
		}*/

		$k = 0;
		foreach ($rows as $row) {
			echo "<items>".chr(10) ;

			$link = 'index.php?option=com_contactxml&amp;task=view&amp;contact_id='. $row->id .'&amp;Itemid='. $Itemid;
					XML_contact::createNodeXML ("link", sefRelToAbs( $link ));
					XML_contact::createNodeXML ("name",$row->name);
				if ( $params->get( 'position' ) ) {
					XML_contact::createNodeXML ("position",$row->con_position); 
				}
				if ( $params->get( 'email' ) ) {
					if ( $row->email_to ) {
						$row->email_to = mosXML::emailCloaking( $row->email_to, 1 );
					}
					XML_contact::createNodeXML ("email", $row->email_to); 
				}
				if ( $params->get( 'telephone' ) ) {
					XML_contact::createNodeXML ("telephone", $row->telephone); 
				}
				if ( $params->get( 'fax' ) ) {
					XML_contact::createNodeXML ("fax", $row->fax); 
				}
			$k = 1 - $k;
			echo "</items>".chr(10) ;

		}
	}

	/**
	* Display links to categories
	*/
	function showCategories( &$params, &$categories, $catid ) {
		global $mosConfig_live_site, $Itemid;
		foreach ( $categories as $cat ) {
			echo "<categories>".chr(10) ;
			if ( $catid == $cat->catid ) {
					XML_contact::createNodeXML ("title",$cat->title);
					XML_contact::createNodeXML ("numLinks",$cat->numlinks);
			} else {
				$link = 'index.php?option=com_contactxml&amp;catid='. $cat->catid .'&amp;Itemid='. $Itemid;
				XML_contact::createNodeXML ("link", sefRelToAbs( $link ));
				XML_contact::createNodeXML ("title", $cat->title);
					if ( $params->get( 'cat_items' ) ) {
						XML_contact::createNodeXML ("numlinks",$cat->numlinks);
					}
					// Writes Category Description
					if ( $params->get( 'cat_description' ) ) {
						XML_contact::createNodeXML ("description",$cat->description);
					}
			}
				echo "</categories>".chr(10) ;

		}
	}


	function viewcontact( &$contact, &$params, $count, &$list, &$menu_params ) {
		global $mosConfig_live_site;
		global $mainframe, $Itemid;
		

		$template 		= $mainframe->getTemplate();
		$sitename 		= $mainframe->getCfg( 'sitename' );

		// For the pop window opened for print preview
		if ( $params->get( 'popup' ) ) {
			$mainframe->setPageTitle( $contact->name );
			$mainframe->addCustomHeadTag( '<link rel="stylesheet" href="templates/'. $template .'/css/template_css.css" type="text/css" />' );
		}

		echo "<contact>".chr(10);

		if ( $menu_params->get( 'page_title' ) ) {

				XML_contact::createNodeXML ("header", $menu_params->get( 'header' )); 
			
		}
		// displays Page Title
		XML_contact::_writePageTitle( $params, $menu_params );

		// displays Contact Select box
		XML_contact::_writeSelectContact( $contact, $params, $count );

		// displays Name & Positione
		XML_contact::_writeContactName( $contact, $params, $menu_params );
					// displays Address
					XML_contact::_writeContactAddress( $contact, $params );

					// displays Email & Telephone
					XML_contact::_writeContactContact( $contact, $params );

					// displays Misc Info
					XML_contact::_writeContactMisc( $contact, $params );

					XML_contact::_writeImage( $contact, $params );
		// displays Email Form
		//XML_contact::_writeVcard( $contact, $params );
		// displays Email Form
		//XML_contact::_writeEmailForm( $contact, $params, $sitename, $menu_params );

		// display Close button in pop-up window
		//mosHTML::CloseButton ( $params, $hide_js );

		// displays back button
		//mosXML::BackButton ( $params, $hide_js );
		echo "</contact>".chr(10);

	}


	/**
	* Writes Page Title
	*/
	function _writePageTitle( &$params, &$menu_params ) {
		if ( $params->get( 'page_title' )  && !$params->get( 'popup' ) ) {
				XML_contact::createNodeXML ("header",$params->get( 'header' ));
		}
	}

	/**
	* Writes Dropdown box to select contact
	*/
	function _writeSelectContact( &$contact, &$params, $count ) {
		if ( ( $count > 1 )  && !$params->get( 'popup' ) && $params->get( 'drop_down' ) ) {
			global $Itemid;
			?>
			<tr>
				<td align="center">
					<br />
					<form action="<?php echo sefRelToAbs( 'index.php?option=com_contactxml&amp;Itemid='. $Itemid ); ?>" method="post" name="selectForm" target="_top" id="selectForm">
						<?php echo (_CONTACT_SEL); ?>
						<br />
						<?php echo $contact->select; ?>
					</form>
				</td>
			</tr>
			<?php
		}
	}

	/**
	* Writes Name & Position
	*/
	function _writeContactName( &$contact, &$params, &$menu_params ) {
		global $Itemid, $hide_js, $mosConfig_live_site;

		if ( $contact->name ||  $contact->con_position ) {
			if ( $contact->name && $params->get( 'name' ) ) {
					XML_contact::createNodeXML ("name",$contact->name);
					//$print_link = $mosConfig_live_site .'/index2.php?option=com_contactxml&amp;task=view&amp;contact_id='. $contact->id .'&amp;Itemid='. $Itemid .'&amp;pop=1';
					//mosHTML::PrintIcon( $contact, $params, $hide_js, $print_link );
				
			}
			if ( $contact->con_position && $params->get( 'position' ) ) {
					XML_contact::createNodeXML ("position", $contact->con_position);
				
			}
		}
	}

	/*
	* Writes Image
	*/
	function _writeImage( &$contact, &$params ) {
		global $mosConfig_live_site;

		if ( $contact->image && $params->get( 'image' ) ) {
			XML_contact::createNodeXML ("image", $mosConfig_live_site."/images/stories/".$contact->image);
		}
	}

	/**
	* Writes Address
	*/
	function _writeContactAddress( &$contact, &$params ) {
		if ( ( $params->get( 'address_check' ) > 0 ) &&  ( $contact->address || $contact->suburb  || $contact->state || $contact->country || $contact->postcode ) ) {
			if ( $params->get( 'address_check' ) > 0 ) {
					//XML_contact::createNodeXML ("markerAddress",$params->get( 'marker_address' ));
			}
			if ( $contact->address && $params->get( 'street_address' ) ) {
					XML_contact::createNodeXML ("streetAddredd",$contact->address);
			}
			if ( $contact->suburb && $params->get( 'suburb' ) ) {
					XML_contact::createNodeXML ("suburb",$contact->suburb);
			}
			if ( $contact->state && $params->get( 'state' ) ) {
					XML_contact::createNodeXML ("state", $contact->state);
			}
			if ( $contact->country && $params->get( 'country' ) ) {
					XML_contact::createNodeXML ("country",$contact->country);
			}
			if ( $contact->postcode && $params->get( 'postcode' ) ) {
					XML_contact::createNodeXML ("postcode", $contact->postcode);
			}
		}
	}

	/**
	* Writes Contact Info
	*/
	function _writeContactContact( &$contact, &$params ) {
		if ( $contact->email_to || $contact->telephone  || $contact->fax ) {
			if ( $contact->email_to && $params->get( 'email' ) ) {
					//XML_contact::createNodeXML ("markerEmail",$params->get( 'marker_email' ));
					XML_contact::createNodeXML ("email", $contact->email);
			}
			if ( $contact->telephone && $params->get( 'telephone' ) ) {
					//XML_contact::createNodeXML ("markerTelephone", $params->get( 'marker_telephone' ));
					XML_contact::createNodeXML ("telephone", $contact->telephone);
			}
			if ( $contact->fax && $params->get( 'fax' ) ) {
					//XML_contact::createNodeXML ("markerFax", $params->get( 'marker_fax' ));
					XML_contact::createNodeXML ("fax", $contact->fax);
			}
		}
	}

	/**
	* Writes Misc Info
	*/
	function _writeContactMisc( &$contact, &$params ) {
		if ( $contact->misc && $params->get( 'misc' ) ) {
				//XML_contact::createNodeXML ("markerMisc", $params->get( 'marker_misc' ));
				XML_contact::createNodeXML ("misc", $contact->misc);
		}
	}

	/**
	* Writes Email form
	*/
	function _writeVcard( &$contact, &$params ) {
		if ( $params->get( 'vcard' ) ) {
			?>
			<tr>
				<td colspan="2">
				<?php echo(_CONTACT_DOWNLOAD_AS);?>
				<a href="index2.php?option=com_contactxml&amp;task=vcard&amp;contact_id=<?php echo $contact->id; ?>&amp;no_XML=1">
				<?php echo(_VCARD);?>
				</a>
				</td>
			</tr>
			<?php
		}
	}

	/**
	* Writes Email form
	*/
	function _writeEmailForm( &$contact, &$params, $sitename, &$menu_params ) {
		global $Itemid;

		if ( $contact->email_to && !$params->get( 'popup' ) && $params->get( 'email_form' ) ) {
			// used for spoof hardening
			$validate = josSpoofValue();
			?>
			<tr>
				<td colspan="2">
				<br />
				<?php echo $params->get( 'email_description' ) ?>
				<br /><br />
				<form action="<?php echo sefRelToAbs( 'index.php?option=com_contactxml&amp;Itemid='. $Itemid ); ?>" method="post" name="emailForm" target="_top" id="emailForm">
				<div class="contact_email<?php echo $menu_params->get( 'pageclass_sfx' ); ?>">
					<label for="contact_name">
						<?php echo(_NAME_PROMPT);?>
					</label>
					<br />
					<input type="text" name="name" id="contact_name" size="30" class="inputbox" value="" />
					<br />
					<label for="contact_email">
						<?php echo(_EMAIL_PROMPT);?>
					</label>
					<br />
					<input type="text" name="email" id="contact_email" size="30" class="inputbox" value="" />
					<br />
					<label for="contact_subject">
						<?php echo(_SUBJECT_PROMPT);?>
					</label>
					<br />
					<input type="text" name="subject" id="contact_subject" size="30" class="inputbox" value="" />
					<br /><br />
					<label for="contact_text">
						<?php echo(_MESSAGE_PROMPT);?>
					</label>
					<br />
					<textarea cols="50" rows="10" name="text" id="contact_text" class="inputbox"></textarea>
					<?php
					if ( $params->get( 'email_copy' ) ) {
						?>
						<br />
							<input type="checkbox" name="email_copy" id="contact_email_copy" value="1"  />
							<label for="contact_email_copy">
								<?php echo(_EMAIL_A_COPY); ?>
							</label>
						<?php
					}
					?>
					<br />
					<br />
					<input type="button" name="send" value="<?php echo(_SEND_BUTTON); ?>" class="button" onclick="validate()" />
				</div>
				<input type="hidden" name="option" value="com_contactxml" />
				<input type="hidden" name="con_id" value="<?php echo $contact->id; ?>" />
				<input type="hidden" name="sitename" value="<?php echo $sitename; ?>" />
				<input type="hidden" name="op" value="sendmail" />
				<input type="hidden" name="<?php echo $validate; ?>" value="1" />
				</form>
				<br />
				</td>
			</tr>
			<?php
		}
	}


	function nocontact( &$params ) {
		XML_contact::createNodeXML ("contactNone", _CONTACT_NONE);
		// displays back button
		//mosXML::BackButton ( $params );
	}
}
?>